from po.base_api import Base_Api
from tools.sqltools import Dbmysql


class Index(Base_Api):
    # def __init__(self):
    #     # 调用父类的方法
    #     super(Index, self).__init__()

    def app_index(self,**kwargs):
        data = {"method": "get", "url": self.host + "/zxx/v4/",
                "params":kwargs
                }
        r = self.send(data)
        return r

    def open_course_list(self,cateid,page,**kwargs):
        data = {
            "method":"get","url":self.host + '/zxx/v4/course/opens',
            "params":{"cateid":cateid,"page":page,**kwargs}
        }
        r = self.send(data)
        return  r


    def open_course_if_not_get(self,para,params,open_course_receive_list):
        '''
        公开课列表中的课程是否被领取
        para: 要取出的value对应的key值:
        params:  r.json()['data']['list']
        open_course_receive_list: r.json()['data']['list']
        '''
        open_course_id_lsit = [num[para] for num in params]
        # 1学员是已领取该公开课   0 未领取
        for par in range(len(open_course_id_lsit)):
            # 查询用户是否领取了公开课
            sql = "select * from zxx_course c  join  zxx_course_learn_record  l on c.id = l.cid where l.uid = 10 and c.id  = {}".format(
                open_course_id_lsit[par])
            sql_res = Dbmysql().query(sql)
            receive_lsit = [num['receive'] for num in open_course_receive_list]  # 公开课领取状态
            if len(sql_res) > 0:
                assert receive_lsit[par] == 1
                print(open_course_id_lsit[par], "已被领取")
            else:
                assert receive_lsit[par] == 0
                print(open_course_id_lsit[par], "未被领取")


    def project_news(self,cateid,**kwargs):
        data = {
            "method":"get","params":{
                "cateid":cateid,**kwargs
            },"url":self.host+'/zxx/v4/news/index'
        }
        r = self.send(data)
        return r

    def project_teacher(self,**kwargs):
        data = {
            "method":"get",
            "params":kwargs,
            "url":self.host+'/zxx/v4/plan/teacher'
        }
        r = self.send(data)
        return r